<template>

    <!-- 通过 -->
    <div class="mui-numbox" data-numbox-min='1'>
        <button class="mui-btn mui-btn-numbox-minus" type="button" @click.stop="numberMinus">-</button>
        <input id="test" class="mui-input-numbox" type="number" value="1" @change.stop="countChanged" v-model="numberValue"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button" @click.stop="numberPlus(max)">+</button>
    </div>
</template>

<script>

    export default {
        data(){
            return{
                numberValue : 1
            }
        },
        methods: {
            countChanged() {
                this.$emit("getcount", parseInt(this.$refs.numbox.value));
            },

            numberMinus(){
                if(this.numberValue > 1){
                    this.numberValue--;
                }
                this.sendCount();
            },

            numberPlus(max){
                if(this.numberValue < max){
                    this.numberValue++;
                } 
                this.sendCount();
            },
            countChanged(max){
                if( this.numberValue > max){
                    this.numberValue = max;
                }
                this.sendCount();
            },
            sendCount(){
                this.$emit('getcount',this.numberValue);
            }
        },
        props: ['max'],
    };
</script>

<style lang="scss" scoped>
    
</style>